package com.hauwei.huaweishop.utils;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;

public class OSSClientUtils {
    private static String endpoint = ConstantPropertiesUtils.END_POINT;
    private static String accessKeyId = ConstantPropertiesUtils.ACCESS_KEY_ID;
    private static String accessKeySecret = ConstantPropertiesUtils.ACCESS_KEY_SECRET;
    private static  String bucket=ConstantPropertiesUtils.BUCKET_NAME;
    private static  String backURL=ConstantPropertiesUtils.BACK_URL;
    public static String putAppImg(String name, byte[] data) {
        OSS client =new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
        InputStream is = new ByteArrayInputStream(data);
        client.putObject(bucket, name, is);
        client.shutdown();
        // 这里写自己的https路径
        return backURL + name;
    }

    public static String putFile(String name, byte[] data) {
        OSS client =new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
        InputStream is = new ByteArrayInputStream(data);
        client.putObject(bucket, name, is);
        client.shutdown();
        // 这里写自己的https路径
        return backURL + name;
    }

    public static String putAppImg(String name, File file) {
        OSS client =new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
        String bucket = "###这里写bucket值###";
        client.putObject(bucket, name, file);
        client.shutdown();
        // 这里写自己的https路径
        return backURL + name;
    }

}
